import { mapGetters } from 'vuex';
import userSelect from './user';
import personSelect from './person';
export default {
	components: { userSelect, personSelect },
	props: {
		userRole: { type: String, default: '' },
		dataType: { type: String, default: '' }
	},
	data() {
		return {
			formData: {
				piList: [],
				collaList: [],
				fundsList: [],
				measureList: [],
			},
			loading: false,
			btnDisabled: false,
			saveLoading: false,
			submitLoading: false
		}
	},
	computed: {
		...mapGetters(['userInfo', 'dictEnums', 'dictConst', 'siteConfig', 'principalData']),
		dataId() {
			return this.$route.query.id || '';
		},
		addOrEdit() {
			return !this.dataId;
		},
		studySectorData() {
			let dataArr = this.siteConfig.filter((n) => n.type === '1');
			return this.$flatToTree(dataArr, 'pid');
		},
		measuringData() {
			return this.siteConfig.filter(n => n.type === '2');
		}
	},
	methods: {
		//格式化研究领域数据
		formatStudySectorData(data) {
			if (!!data.sector && !this.studySectorData.some(n => n.name === data.sector)) {
				this.otherSector = data.sector;
				this.$set(data, 'sector', 0);
				this.$delete(data, 'filed4');
			}
		},

		//保存表单数据
		handleSaveFormData(params) {
			let returns = [];
			this.$refs['form'].validateField(params, err => {
				!err && returns.push(!err);
				if (returns.length === params.length) {
					this.formData['isSave'] = '2';
					this.submitFormRequest();
				} else {
					this.saveLoading = false;
				}
			});
		},

		//预览数据
		handlePreviewData() {},

		//下载模板
		handleDownloadTemp(type) {
			window.location.href = `${window.baseUrl}tbTopic/down/${type}`;
		}
	}
}